<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('排水管养列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            清单状态：<select name="status" th:with="type=${@dict.getType('sys_pipe_status')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>
                        <li>
                            <p>联系人: </p>
                            <input type="text" name="contact"/>
                        </li>
                        <li>
                            <p>联系电话：</p>
                            <input type="text" name="telephone"/>
                        </li>
                        <li>
                            <p>所属辖区：</p>
                            <input type="text" name="memberArea"/>
                        </li>
                        <li>
                            <p>问题地点：</p>
                            <input type="text" name="issuePalce"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="process:maintainence:add">
                <i class="fa fa-plus"></i> 添加
            </a>
          <!--  <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="process:maintainence:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="process:maintainence:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()"
               shiro:hasPermission="process:maintainence:export">
                <i class="fa fa-download"></i> 导出
            </a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">

    var editFlag = [[${@permission.hasPermi('process:maintainence:edit')}]];
    var removeFlag = [[${@permission.hasPermi('process:maintainence:remove')}]];
    var datas1 = [[${@dict.getType('sys_pipe_status')}]];
    var datas2 = [[${@dict.getType('sys_yes_no')}]];
    var prefix = ctx + "process/maintainence";
    var currentUser = [[${currentUser}]];
    var userId = currentUser.userId.toString();

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            detailUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "排水管养",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'createBy',
                    title: '创建人id',
                    visible: false
                },
                {
                    field: 'createByUserName',
                    title: '创建人'
                },
                {
                    field: 'status',
                    title: '清单状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas1, value);
                    }
                },
                {
                    field: 'problemSources',
                    title: '问题来源',
                    visible: false
                },
                {
                    field: 'reportTime',
                    title: '上报时间',
                    visible: false
                },
                {
                    field: 'contact',
                    title: '联系人'
                },
                {
                    field: 'telephone',
                    title: '联系电话'
                },
                {
                    field: 'taskId',
                    title: '任务id'
                },
                {
                    field: 'processInstanceId',
                    title: '流程实例id',
                    visible: false
                },
                {
                    field: 'bigClassName',
                    title: '大类',
                    visible: false
                },
                {
                    field: 'smallClassName',
                    title: '小类',
                    visible: false
                },
                {
                    field: 'associatedOfficeNum',
                    title: '关联办件号',
                    visible: false
                },
                {
                    field: 'problemDescription',
                    title: '问题描述',
                    visible: false
                },
                {
                    field: 'isDifficultParts',
                    title: '是否疑难件',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas2, value);
                    }
                },
                {
                    field: 'solveDeadline',
                    title: '解决期限',
                    visible: false
                },
                {
                    field: 'expirationTime',
                    title: '到期时间',
                    visible: false
                },
                {
                    field: 'length',
                    title: '长度(m)',
                    visible: false
                },
                {
                    field: 'width',
                    title: '宽度(m)',
                    visible: false
                },
                {
                    field: 'area',
                    title: '面积(m^2)',
                    visible: false
                },
                {
                    field: 'memberArea',
                    title: '所属辖区'
                },
                {
                    field: 'issuePalce',
                    title: '问题地点'
                },
                {
                    field: 'remark',
                    title: '备注',
                    visible: false
                },
                {
                    field: 'solveDepartment',
                    title: '处理部门'
                },
                {
                    field: 'taskName',
                    title: '当前任务名称',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return '<span class="badge badge-primary">' + value + '</span>';
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (row.processInstanceId) {
                            actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-eye"></i> 查看详情</a> ');
                            actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="showHistoryDialog(\'' + row.processInstanceId + '\')"><i class="fa fa-list"></i> 审批历史</a> ');
                            actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="showProcessImgDialog(\'' + row.processInstanceId + '\')"><i class="fa fa-image"></i> 进度查看</a> ');
                        } else {
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="submitApply(\'' + row.id + '\',\'' + row.createBy + '\')"><i class="fa fa-user"></i> 提交申请</a> ');
                            actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="editForm(\'' + row.id + '\',\'' + row.createBy + '\')"><i class="fa fa-edit"></i> 编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="removeForm(\'' + row.id + '\',\'' + row.createBy + '\')"><i class="fa fa-remove"></i> 删除</a>');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function submitApply(id, createBy) {
        debugger
        if (createBy !== userId) {
            $.modal.alertWarning("不允许非创建人提交申请！");
            return;
        }
        $.modal.confirm("确认要提交申请吗?", function () {
            var url = prefix + "/submitApply";
            var data = {"id": id};
            $.operate.submit(url, "post", "json", data);
        });
    }

    function editForm(id, createBy) {
        debugger
        if (createBy !== userId) {
            $.modal.alertWarning("不允许非创建人编辑表单！");
            return;
        }
        $.operate.edit(id);
    }

    function removeForm(id, createBy) {
        if (createBy !== userId) {
            $.modal.alertWarning("不允许非创建人删除表单！");
            return;
        }
        $.operate.remove(id);
    }

    /* 查看审批历史 */
    function showHistoryDialog(instanceId) {
        var url = ctx + 'process/general/historyList/' + instanceId;
        $.modal.open("查看审批历史", url);
    }

    function showProcessImgDialog(instanceId) {
        var url = ctx + 'process/general/processImg/' + instanceId;
        $.modal.open("查看流程图 (标红表示已结束或活动中的流程)", url, "1200");
    }

</script>
</body>
</html>